
<div class="personal w1200">

<div class="management f-r">
    <div class="tanchuang-con">
        <div class="tc-title">
            <h3>我的收货地址</h3>
        </div>
        <font class="xinxi">请认真填写以下信息！</font>
        <ul class="tc-con2">
            <li class="tc-li1">
                <p class="l-p">所在地区<span>*</span></p>
                <div class="xl-dz">
                    <div class="dz-left f-l">
                        <p>请选择</p>
                        <ul>

                            <?php foreach($list as $key=>$value){
                                echo '   <li  onclick="getCity('.$value['Id'].')" ><a href="#">'.$value['Name'].'</a></li>';

                            } ?>

                        </ul>
                    </div>

                    <script>
                        var province = null;
                        var city = null;
                        function citychose(id,name){
                            city = id;
                            $("#cityp").html(name)
                            $("#cityUl").hide()
                        }
                        function getCity(id){
                            province = id;
                            $.ajax({

                                type: 'POST',
                                url: '<?php echo Url::base(); ?>index.php/chinam/getCity?id='+ province,
                                success: function(data){
                                    console.log(data)
                                    for(var i = 0 ;i<data.length;i++){
                                        $("#cityUl").append('<li onclick="citychose('+data[i]['Id']+',\''+data[i]['Name']+'\')" ><a href="#" >'+data[i]['Name']+'</a></li>');
                                    }
                                } ,
                                dataType: "json"

                            });
                        }
                        function save(){
                            if(province == null){alert("请选择所在地区");return false;}
                            if(city == null){alert("请选择城市");return false;}
                            if(document.getElementById('address').value == ""){alert("请填写地址");return false;}
                            if(document.getElementById('reviceName').value==""){alert("请填写收货人姓名");return false;}
                            if($("#phone").val()==""||!/^(17[0-9]|13[0-9]|14[0-9]|15[0-9]|18[0-9])\d{8}$/i.test($("#phone").val())){alert("请填写正确格式手机号");return false;}

                            $.ajax({
                                data:{
                                    provinceId:province,
                                    cityId:city,
                                    address:document.getElementById('address').value,
                                    username:document.getElementById('reviceName').value,
                                    phone:$("#phone").val(),
                                    isDefault:$("#isDefault").val()
                                },
                                type: 'POST',
                                url: '<?php echo Url::base(); ?>index.php/user/insertAddress',
                                success: function(data){
                                    if(data.msg ){
                                        alert("添加成功")
                                        window.location.reload();
                                    }else{
                                        alert(data.data)
                                    }
                                } ,
                                dataType: "json"

                            });
                        }
                    </script>
                    <div class="dz-right f-l">
                        <p id="cityp">请选择</p>
                        <ul id="cityUl">

                        </ul>
                    </div>
                    <div style="clear:both;"></div>
                </div>
                <div style="clear:both;"></div>
            </li>
            <li class="tc-li1">
                <p class="l-p">详细地址<span>*</span></p>
                <textarea  id="address" class="textarea1" placeholder="请如实填写您的详细信息，如街道名称、门牌号、楼层号和房间号。"></textarea>
                <div style="clear:both;"></div>
            </li>

            <li class="tc-li1">
                <p class="l-p">收货人姓名<span>*</span></p>
                <input type="text"  id="reviceName"/>
                <div style="clear:both;"></div>
            </li>

            <li class="tc-li1">
                <p class="l-p">默认<span>*</span></p>
                <select id="isDefault">

                    <option value="默认" selected>默认</option>
                    <option value="未默认" >未默认</option>
                </select>
                <div style="clear:both;"></div>
            </li>
            <li class="tc-li1">
                <p class="l-p">联系电话<span>*</span></p>
                <input type="text" id="phone" />
                <div style="clear:both;"></div>
            </li>
        </ul>
        <button class="btn-pst2" onclick="save()">保存</button>
    </div>
    <div class="man-info">
        <font>您已经保存三个地址！</font>
        <div class="man-if-con">
            <div class="man-tit">
                <p class="p1">收货人</p>
                <p class="p2">所在地区</p>
                <p class="p3">详细地址</p>
                <p class="p5">电话/手机</p>
                <p class="p6">操作</p>
            </div>
            <ul class="man-ul1">

                <?php
                foreach($address as $key=>$value){
?>
                <li>
                    <p class="p1"><?php echo $value['username'];?></p>
                    <p class="p2"><?php echo $value['provinceName'];?> <?php echo $value['cityName'];?></p>
                    <p class="p3"><?php echo $value['address'];?></p>
                    <p class="p5"><?php echo $value['phone'];?></p>
                    <p class="p6">
                        <a href="<?php echo Url::base(); ?>index.php/user/deleteAddress?id=<?php echo $value['id'];?>">删除</a>
                    </p>
                    <p class="p7"><a href="#"><?php echo $value['isDefault']=='默认'?'默认地址':'';?></a></p>
                    <div style="clear:both;"></div>
                </li>
<?php }?>
            </ul>
        </div>
    </div>
</div>
<div style="clear:both;"></div>
</div>